package com.mall.service.impl.sys;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.mall.entity.sys.ProductEO;
import com.mall.exception.MsgException;
import com.mall.mapper.sys.ProductMapper;
import com.mall.service.sys.IProductService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * <p>
 * 商品表  服务实现类
 * </p>
 *
 * @author Dczzs
 * @since 2020-06-30
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductEO> implements IProductService {

	@Override
	public boolean delete(Integer id) {
		  boolean yn = 	removeById(id);
		  if(yn) {
			  return true;
		  }else {
			  
			  throw new MsgException("删除失败！！！");
		  }
			
		}
 
	@Override
	public ProductEO queryById(Integer id) {
		return baseMapper.queryById(id);
	}

	@Override
	public Map<String, Object> newProd() {
		Map<String, Object> newprod = Maps.newHashMap();
		
		Page<ProductEO> page = page(new Page<>(1, 10),new QueryWrapper<ProductEO>().orderByDesc("created_time"));
		Page<ProductEO> kucun = page(new Page<>(1, 10),new QueryWrapper<ProductEO>().orderByAsc("kucun"));	
		Page<ProductEO> price = page(new Page<>(1, 3),new QueryWrapper<ProductEO>().orderByDesc("price"));

		
		IPage<ProductEO> page_nvzhuang = getBaseMapper().queryByParentTypeId(new Page<>(1, 10), 1);
		
		newprod.put("all", page.getRecords());
//		newprod.put("女装", page_nvzhuang.getRecords());
		
		newprod.put("kucun",kucun.getRecords());
//		newprod.put("库存",kucun.getRecords());
		
//		IPage<ProductEO> jiaqian = getBaseMapper().queryByParentTypeId(new Page<>(1,1), 14);	
//		newprod.put("价钱", price.getRecords());
		newprod.put("price",price.getRecords());

		
		
		return newprod;
		
		}

	@Override
	public List<ProductEO> queryHDListByType1() {
		return getBaseMapper().queryHDListByType1();
	}

	@Override
	public List<ProductEO> queryHDListByType2() {
		return getBaseMapper().queryHDListByType2();
	}
	}


